package scd;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Collection;


class PersonSortable{
	private String name;
	private int age;


	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
	}

	
	public void setName(String name){
		this.name=name;
	}
	public void setAge(int age){
		this.age=age;
	}
	
    public String getName() {
        return name;
    }
    public int getAge() {
        return age;
    }
	@Override
	public String toString() {
		return name + "-" + age;
	}

}
    
   class NameComparator implements Comparator<PersonSortable>  {
    	public int compare(PersonSortable o,PersonSortable o1){
    		return o.getName().compareTo(o1.getName());
    	}

	}
    class AgeComparator implements Comparator<PersonSortable>  {
    	public int compare(PersonSortable o,PersonSortable o1){
    		return o.getAge()-o1.getAge();
    	}

	}




public class Main2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PersonSortable[] stus = new PersonSortable[n];
		for (int i = 0; i < n; i++) {
			stus[i] = new PersonSortable(sc.next(), sc.nextInt());
		}
		Arrays.sort(stus,new NameComparator());
		System.out.println("NameComparator:sort");
		for (int i = 0; i < n; i++) {
			System.out.println(stus[i]);
		}
		Arrays.sort(stus,new AgeComparator());
		System.out.println("AgeComparator:sort");
		for (int i = 0; i < n; i++) {
			System.out.println(stus[i]);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));

	}


}